package prod_line

import (
	"errors"
	"github.com/lishimeng/app-starter/stream"
)

var (
	CommunicateErr = errors.New("Serial error")
)

var session stream.Session

type ProductionLine struct {
}

// OnProcessStart 模具就位B0
func (s *sdk) OnProcessStart(h func()) {
	s.processStartListener = h
}

// OnCheckConfirm 检测结果确认
func (s *sdk) OnCheckConfirm(h func()) {
	s.checkConfirmListener = h
}

func (s *sdk) OnCodingResultConfirm(h func()) {
	s.codingResultConfirmListener = h
}

func (s *sdk) Coding(h func()) {
	s.codingRequestListener = h
}
func (s *sdk) Recoding(h func()) {
	s.recodingRequestListener = h
}

// CheckReply 回复检查结果
func (s *sdk) CheckReply(cr CheckResult) (err error) {
	for _, item := range cr.Items {
		if len(item.Uid) != 6 {
			err = errors.New("UID长度必须是6字节")
			return
		}
	}
	s.sendCheckResult(cr)
	return
}

// CodingReply 赋码结果
func (s *sdk) CodingReply(cr CodingResult) (err error) {
	// TODO
	for _, item := range cr.Items {
		if len(item.DetonatorCode) != 13 {
			err = errors.New("管壳码长度必须是13字节")
			return
		}
	}
	s.sendCodingResult(cr)
	return
}

// OnProcessComplete 结束
func (s *sdk) OnProcessComplete(h func(result bool)) {
	s.completedListener = h
}

// Test 设备测试
func (s *sdk) Test() {

}
